<template>
    <div>
        名称：{{ entityData?.entity.name }}
        <n-divider vertical />
        <noteTypeTag :type="entityData?.note.type" />
        <algorithmTypeTag :type="entityData?.note.algorithmType" :name="entityData?.note.algorithmName" />
        <equipmentTypeTag :type="entityData?.note.equipmentType" :name="entityData?.note.equipmentName" />
        <n-divider title-placement="left"> 最新的记录</n-divider>
        <n-ellipsis :line-clamp="2">
            {{ entityData?.note.content }}
        </n-ellipsis>
    </div>
    <notes :entity-id="data.entityId" :entity-name="entityData?.entity.name"  v-if="data.entityId!==0"/>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { NDivider ,NEllipsis} from 'naive-ui'
import notes from './components/notes.vue'
import noteTypeTag from './components/noteTypeTag.vue'
import algorithmTypeTag from './components/algorithmTypeTag.vue'
import equipmentTypeTag from './components/equipmentTypeTag.vue'
import requset from "@/utils/requset"
import { getAlgorithmList, getEquipmentList } from "./request"
import type { response } from "@/utils/requset"
import type { entityRespone, algorithmResopne, equipmentResopne } from "@/utils/interfaces/respone"

const router = useRouter()

// const childrenProps = ref({
//     pointId: 0,
//     // algorithm: 0,
// })

const data = ref({
    entityId: 0,
    pointId: 0,
    algorithm: 0,
    equipment: 0,
})

const entityData = ref<entityRespone>()
const algorithmList = ref<algorithmResopne[]>()
const equipmentList = ref<equipmentResopne[]>()

function getData() {
    requset.get('/project/getEntityWithLastNoteById', {
        entityId: data.value.entityId
    }).then((res: response<entityRespone>) => {
        if (res.status !== 200) {
            return;
        }
        let data = res.data.data;
        entityData.value = data;
    })
}

onMounted(() => {
    let entityIdIn = Number(router.currentRoute.value.query.entityId)
    if (Number.isNaN(entityIdIn) || entityIdIn == null || entityIdIn == 0) {
        entityIdIn = 0
    }
    data.value.entityId = entityIdIn
    let pointIdIn = Number(router.currentRoute.value.query.pointId)
    if (Number.isNaN(pointIdIn) || pointIdIn == null || pointIdIn == 0) {
        pointIdIn = 0
    }
    data.value.pointId = pointIdIn
    getData()
    getAlgorithmList(pointIdIn).then(algorithmListRes => {
        algorithmList.value = algorithmListRes
    })
    getEquipmentList(pointIdIn).then(equipmentListRes => {
        equipmentList.value = equipmentListRes
    })
})

</script>

<style></style>